package cn.edu.ctbu.lddweb.controller;

import cn.edu.ctbu.lddweb.pojo.Score;
import cn.edu.ctbu.lddweb.pojo.Semester;
import cn.edu.ctbu.lddweb.service.ScoreService;
import cn.edu.ctbu.lddweb.service.SemesterService;
import cn.edu.ctbu.lddweb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 学生查看个人成绩
 */
@Controller
public class Score_sController {
    @Autowired
    private ScoreService scoreService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private SemesterService semesterService;

    //教师查看学生成绩
    @RequestMapping("/studentScore/index")
    public String index(Model model, ModelMap map, String username, Score score){
        score.setStudentName(username);
        List<Score> list = scoreService.selectScore_S(score);
        model.addAttribute("score",list);

        //学期下拉列表
        Semester semester = new Semester();
        List<Semester> list1 = semesterService.selectList(semester);
        model.addAttribute("semester",list1);

        map.put("username",username);
        return "/studentScore/index";
    }

    //搜索/重置
    @RequestMapping("/selectScore2")
    public String selectScore2( @RequestParam(value = "semesterName",required = false) String semesterName,  @RequestParam(value = "username",required = false) String username, Model model,ModelMap map){
        Score score = new Score();
        score.setStudentName(username);
        score.setSemesterName(semesterName);
        List<Score> list = scoreService.selectScore_S(score);
        model.addAttribute("score",list);

        //学期下拉列表
        Semester semester = new Semester();
        List<Semester> list1 = semesterService.selectList(semester);
        model.addAttribute("semester",list1);


        map.put("username",username);
        return "/studentScore/index";
    }
}
